/*  dreic -- a compiler for Drei
 *
 *  $Id: AnalyzerTest.scala 3228 2006-12-07 02:05:31Z dubochet $
 */

package dreic


/** A small test class for the semantic analyzer of dreic; it reads
 *  in a file and prints out the abstract syntax tree. If the program
 *  is erroneous, the compiler will print a corresponding error message
 *  instead.
 *
 *  usage: scala dreic.AnalyzerTest <file.drei>
 */
object AnalyzerTest {
  import java.io.{FileInputStream, IOException}

  def main(args: Array[String]): Unit = {
    if (args.length != 1) {
      Report.fail("usage: scala dreic.AnalyzerTest <file.drei>")
    }
    try {
      val in = new FileInputStream(args(0))
      val tree = new Parser(in).parse
      in.close()
      if (Report.errors == 0)
        new Analyzer().analyzeProgram(tree)
      Report.exit()
    }
    catch {
      case e: IOException => Report.fail(e.getMessage())
    }
  }

}
